<template>
  <div >
    <div>
      <input placeholder="请输入上课时间" v-model="times"/>
      <input placeholder="请输入教师姓名" v-model="T_name"/>
    </div>

    <div >
      <mt-button  type="default" @click="get_TestData">查询</mt-button>
    </div>

    <h4>课程基本信息</h4>
    <mt-field label="教师姓名："  >{{this.S_result.teacher}}</mt-field>
    <mt-field label="课程姓名："  >{{this.S_result.courses}}</mt-field>
    <mt-field label="院系："  >{{this.S_result.college}}：{{this.S_result.department}}</mt-field>
    <mt-field label="教室："  >{{this.S_result.addr}}</mt-field>
    <mt-field label="上课时间："  >{{this.S_result.week}}：{{this.S_result.time}}</mt-field>
    <h4>签到信息</h4>
    <mt-field label="总人数："  type="number">{{this.Sin_in_num+this.N0_sin_in_num}}</mt-field>
    <mt-field label="签到人数："  type="number">{{this.Sin_in_num}}</mt-field>
    <mt-field label="未签到人数：" type="number" >{{this.N0_sin_in_num}}</mt-field>
    <h6>未签到学号：</h6>
      <ol>
        <li v-for="item in Sin_Info">
          {{item.number}}
        </li>
      </ol>


  </div>


</template>

<script>
  import { Search } from 'mint-ui';
  import { Field } from 'mint-ui';
  import { Cell } from 'mint-ui';
  import axios from 'axios';
  import { MessageBox } from 'mint-ui';
  import qs from 'qs';
  export default {
    name: "tea-sigin-content",
    data:function () {
      return{
        //自定义的对象
        S_result:[],
        Sin_Info:[],
        Sin_in_num:'',
        N0_sin_in_num:'',
        //数据库对象
        value:'',
        teacher:'',
        addr:'',
        college:'',
        courses:'',
        mylass:'',
        professional:'',
        school:'',
        time:'',
        week:'',
        department:'',
        //v-modle对象
        times:'',
        T_name:''
      }
    },
    components:{
      MtSearch:Search,
      MtField:Field,
      Mtcell:Cell
    },

    methods:{
      get_TestData:function () {
        var _this = this;
        var j = 0;
        _this.get_SignData();
        axios.get('http://23.83.244.88:8080/schedule')
          .then(function (response) {
            console.log(response.data);
            console.log("数据response的长度是：",response.data.length);
            for (var i = 0;i<response.data.length;i++){
              if(_this.equalsIgnoreCase(_this.T_name, response.data[i].teacher)&&_this.equalsIgnoreCase(_this.times, response.data[i].time)){
                _this.S_result=response.data[i];
                break;
              }else {
                if(i == response.data.length-1){
                  MessageBox('输入的查询条件错误，请重新输入');
                  _this.Input_agin();
                }
              }
            }
          })
          .catch(function (error) {
            console.log(error);
          });
      },
      equalsIgnoreCase:function (str1,str2) {
        if(str1.toUpperCase() == str2.toUpperCase())
        {
          return true;
        }
        return false;
      },
      get_SignData:function () {
        var _this = this;
        var Sum = 56;
        // axios().then().catch()
       axios.get('http://23.83.244.88:8080/request_sign_in').then(function (res) {
            console.log(res.data)
          _this.Sin_Info = res.data
         _this.Sin_in_num = Sum - _this.Sin_Info.length;
            _this.N0_sin_in_num = _this.Sin_Info.length;
         console.log(_this.Sin_Info.length)
         }
        ).catch(function (error) {
          console.log(error)
       })
      },
      Input_agin:function () {
        this.times = null;
        this.T_name = null
      }
    }

  }
</script>

<style >

</style>
